// var  send = () => {
//     document.getElementById("floatContent").innerHTML = `
//     <div class="floatTop">请输入图片中的数字</div>
//     <button id="close" onclick="click()"><i class="fa fa-times  fa-2x" aria-hidden="true"></i></button>
//     <canvas id="canvas" onclick="dr()"></canvas>
//     <input type="text" id="codetext" name="ps" class="inputFirst" placeholder="请输入验证码">
//     <button id="yes" onclick="sublim();close()">确定</button>
//     </div>`
//     document.getElementById("floatContent").classList.remove("hide");
//     document.getElementById("close").onclick = function () {
//         close()        
//     }
//     draw(show_num);  
// }
// var show_num = [];
// function dr(){
// draw(show_num);   
// }
// function sublim(){
//     var val=document.getElementById("codetext").value;  
//     var num = show_num.join("");//把数组元素转换为字符串
//     if(val==''){
//         alert('请输入验证码！');
//     }else if(val == num){
//         alert('提交成功！');
//         sendma();
//     }else{
//         alert('验证码错误！请重新输入！');
//         document.getElementById("text").value='';
//         draw(show_num);
//     }
// }
// function draw(show_num) {
//     var canvas_width=document.getElementById('canvas').clientWidth;
//     var canvas_height=document.getElementById('canvas').clientHeight;
//     var canvas = document.getElementById("canvas");//获取到canvas的对象，演员
//     var context = canvas.getContext("2d");//获取到canvas画图的环境，演员表演的舞台
//     canvas.width = canvas_width;
//     canvas.height = canvas_height;
//     var sCode = "A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0,q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m";
//     var aCode = sCode.split(",");
//     var aLength = aCode.length;//获取到数组的长度

// const { response } = require("express");

        
//     for (var i = 0; i <= 3; i++) {
//         var j = Math.floor(Math.random() * aLength);//获取到随机的索引值
//         var deg = (Math.random() * 30 * Math.PI / 180); //产生0~30之间的随机弧度
//         var txt = aCode[j];//得到随机的一个内容
//         show_num[i] = txt;
//         var x = 10 + i * 20;//文字在canvas上的x坐标 
//         var y = 20 + Math.random() * 8;//文字在canvas上的y坐标
//         context.font = "bold 23px 微软雅黑";    //文字样式

//         context.translate(x, y);
//         context.rotate(deg);

//         context.fillStyle = randomColor();
//         context.fillText(txt, 0, 0);     //加入文本

//         context.rotate(-deg);            //角度变换
//         context.translate(-x, -y);       //位置变换
//     }
//     for (var i = 0; i <= 5; i++) { //验证码上显示线条 ，5条线
//         context.strokeStyle = randomColor();
//         context.beginPath();         //开始一条路径
//         context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
//         context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);   //创建从哪到哪的一条线
//         context.stroke();          //绘制一条路径
//     }
//     for (var i = 0; i <= 30; i++) { //验证码上显示小点 ，30个点
//         context.strokeStyle = randomColor();
//         context.beginPath();         //开始一条路径
//         var x = Math.random() * canvas_width;
//         var y = Math.random() * canvas_height;
//         context.moveTo(x, y);
//         context.lineTo(x + 1, y + 1);//同样是线，但是因为长度为1，就变成了点
//         context.stroke();           //绘制一条路径
//     }
// }
// function randomColor() {//得到随机的颜色值
//     var r = Math.floor(Math.random() * 256);
//     var g = Math.floor(Math.random() * 256);
//     var b = Math.floor(Math.random() * 256);
//     return "rgb(" + r + "," + g + "," + b + ")";
// }
function close() {
    document.getElementById("floatContent").classList.add("hide");
}
// function sendma(){
//     var email = document.getElementById("email").value;
//     var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
//     if (!myreg.test(email)) {
//         document.getElementById("floatContent").innerHTML = "<div>" + "提示\n请输入有效的E_mail！" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//         document.getElementById("floatContent").classList.remove("hide");
//     } else {
//         axios.get('/home/register/email/sendAuthCodeEmail',{
//             params:{
//                 email: email,
//             }
//         }).then(function (data) {
//             var totalTime = 60;
//             if (data.data.data.code == 20000) {
//                 document.getElementById("send").style.backgroundColor='lightgray'
//                 document.getElementById("send").style.color='white'
//                 document.getElementById("noclick").style.display='block'
//                 let clock = window.setInterval(() =>{
//                     totalTime--;
//                     document.getElementById("send").innerHTML = totalTime+'s后重新发送'
//                     if(totalTime == 0){
//                         document.getElementById("send").style.backgroundColor='#F96C0C'
//                         document.getElementById("send").style.color='white'
//                         document.getElementById("noclick").style.display='none'
//                         window.clearInterval(clock)
//                         document.getElementById("send").innerHTML = '重新发送'
//                         totalTime = 60;
//                     }
//                 },1000)
//                 document.getElementById("floatContent").innerHTML = "<div>" + "验证码已发送" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//                 document.getElementById("floatContent").classList.remove("hide");
//             }else{
//                 document.getElementById("floatContent").innerHTML = "<div>" + "验证码发送失败" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//                 document.getElementById("floatContent").classList.remove("hide");
//             }
//         }).catch(function (error) {
//             console.log(error)
//             document.getElementById("floatContent").innerHTML = "<div>" + "请检查网络状况" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
//             document.getElementById("floatContent").classList.remove("hide");
//         })
//     };
// }
window.onload = function () {
    var serveornot = localStorage.getItem("serveornot")
    if (serveornot==1){
        var servename = localStorage.getItem("servename")
        var servepassword = localStorage.getItem("servepassword")
        document.getElementById("username").value=servename;
        document.getElementById("password").value=servepassword;
        document.getElementById("yes").checked=true;
    }
    document.getElementById("up").onclick=function () {
        var account=document.getElementById("username").value;
        var password=document.getElementById("password").value;
        var code = document.getElementById("text").value;
        console.log("验证码是"+code)
        if(typeof(account)=="undefined"){
            document.getElementById("floatContent").innerHTML = "<div>" + "用户名不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
            document.getElementById("floatContent").classList.remove("hide");
        }else if(typeof(password)=="undefined"){
            document.getElementById("floatContent").innerHTML = "<div>" + "密码不能为空" + "</div>" + "<button onclick='closethis()' class='newbtn'>" + "确定" + "</button>";
            document.getElementById("floatContent").classList.remove("hide");
        }else{
        axios.get('/home/login/user/loginByPassword',{
            params:{
                email:account,
                password:password,
                code:code
            }
        }).then(function(data){ 
            console.log(data)
            console.log("------------------")
            console.log(data)
            console.log(data.data)
            console.log(data.data.data.flag)
            console.log("------------------")
            if(data.data.code==20000){
                // location.href="/home"
                if(data.data.data.flag == 0){
                    location.href="/home/center"
                }else if(data.data.data.flag == 1){
                    location.href="/home/shopstage"
                }else{
                    location.href="/admin"
                }
                // console.log(data.userInfo);
                var list = data.data;
                // console.log(1)
                // console.log(list)
                // console.log(1)
                // console.log(list.data)//{password: 'f4e21814c5cf8c75e4667eb8828e0e0c', img: 'https://shopwall-1305869108.cos.ap-nanjing.myqclou…com/shopwall/13cf500c433d4a049e8ec5a44c8b1391.png', flag: '0', sex: '男', nickname: 'maohaichao', …}
                // console.log(1)
                // console.log(list.data.id)
                // console.log(1)
                if(document.getElementById("yes").checked){
                    localStorage.setItem("servename",account)
                    localStorage.setItem("servepassword",password)
                    localStorage.setItem("serveornot",1)
                }else{
                    localStorage.removeItem("servename")
                    localStorage.removeItem("servepassword")
                    localStorage.removeItem("serveornot")
                }
                document.getElementById("floatContent").innerHTML ="<div>"+ "欢迎您"+account+"</div>"+"<div>"+"登录成功"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
                document.getElementById("floatContent").classList.remove("hide");
            }else{
                document.getElementById("floatContent").innerHTML ="<div>"+ "很抱歉"+account+"</div>"+"<div>"+"登录失败"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
                document.getElementById("floatContent").classList.remove("hide");
            }
        }).catch(function (error){
            document.getElementById("floatContent").innerHTML ="<div>"+ "很抱歉"+account+"</div>"+"<div>"+"请检查网络情况"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
            document.getElementById("floatContent").classList.remove("hide");
        })
        }
    }
}

function getKaptch(){
    var email = document.getElementById("username").value
    axios.get('/home/login/kaptch',{
        params:{
            email:email,
        },
        // responseType:"blob"
    }).then(function(data){
        console.log(data)
        // let blob = new Blob([data.data], {type: "image/png"});
		// let url = window.URL.createObjectURL(blob);
        // console.log(url)
        // //blob转为base64
		// 	var reader = new FileReader();
		//     reader.readAsDataURL(blob);

        //     reader.addEventListener('load', function () {
		// 	//    console.log(e.target.result)
        //        document.getElementById("send").src = this.result;
		//     } ,false);

		    // reader.onload = function (e) {
			//    console.log(e.target.result)
            //    document.getElementById("send").src = this.result;
		    // } 
        // document.getElementById("send").src =`${data.data.data.data}`

        document.getElementById('send').setAttribute( 'src', `data:image/jpg;base64,${data.data.data.data}` );
        document.getElementById("onsend").classList.add("hide")
    }).catch(function (error){
        console.log(error)
        document.getElementById("floatContent").innerHTML =`<div>很抱歉</div><div>请检查网络连接</div><button onclick='closethis()' class='newbtn'>确定</button>`;
        document.getElementById("floatContent").classList.remove("hide");
    })
}


function  closethis(){
    document.getElementById("floatContent").classList.add("hide");
}